package com.yc.tomcat.impl;

import com.yc.tomcat.HttpServlet;
import com.yc.tomcat.HttpServletRequest;
import com.yc.tomcat.HttpServletResponse;
import com.yc.tomcat.ServletException;

import java.io.IOException;

public class HttpServletImpl implements HttpServlet {
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        switch (request.getMethod()) {
            case "GET": doGet(request,response); break;
            case "POST": doPost(request,response); break;
            // TODO 请扩展其它的方法
        }
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("不支持该请求类型: GET");
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        throw new ServletException("不支持该请求类型: POST");
    }

    @Override
    public void doOptions(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        // TODO
    }

    @Override
    public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// TODO
    }

    @Override
    public void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// TODO
    }

    @Override
    public void doTrace(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// TODO
    }

    @Override
    public void init() {

    }

    @Override
    public void destroy() {

    }
}
